package com.bicycle.rentalsystem.servelt.admin;

import com.bicycle.rentalsystem.pojo.admin.Bicycle;
import com.bicycle.rentalsystem.service.admin.BicycleService;
import com.bicycle.rentalsystem.service.impl.admin.BicycleServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(value = {"/bicycleServlet","/user/u_index"})
public class BicycleServlet extends HttpServlet {
    BicycleService bicycleService=new BicycleServiceImpl();
    protected void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.查询全部自行车
        List<Bicycle> list = bicycleService.searchBicycles();
        //2.自行车保存到request域中
        req.setAttribute("list",list);
        //3.请求转发
        req.getRequestDispatcher("a.jsp").forward(req,resp);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Bicycle> list = bicycleService.searchBicycles();
        //2.自行车保存到request域中
        HttpSession session = req.getSession();
        session.setAttribute("bikeList",list);
        //3.请求转发
        resp.sendRedirect("u_index.jsp");
    }
}
